<?php

$peer = OrdersPeer::getInstance();
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');
$order = $peer->find($id)->current();
if (!$order) $order = OrdersPeer::getInstance()->createRow();


$form = $this->element;

/* @var $productRow ProductRow */
if ($form->getRow()) {
	$productRow = $form->getRow()->getRow();
} else {
	$productRow = ProductPeer::getInstance()->createRow();
}

foreach ($form->getElements() as $e) {
	if ($e instanceof Zend_Form_Element_Checkbox) {
		$label = $e->getDecorator('Label');
		$label->setOption('placement', Zend_Form_Decorator_Abstract::APPEND);
		$label->setTag('dd');
		
		$tag = $e->getDecorator('HtmlTag');
		$tag->setTag('dt');
		//$e->removeDecorator('Label');
		//$e->addDecorator($label);
		
		//echo '<pre>';
		//var_dump($e->getDecorators());die();
	}
}

function getMonthsByAge($yearsByMonth, $currentMonth = '') {
	$str = '';
	$helper = new Helpers_PluralMonths();
	for ($month = 0, $year = 1; $month < $yearsByMonth;) {
		if ($month < 23) {
			++$month;
		} else {
			$month = ++$year*12;
		}
		
		$selected = '';
		if ($currentMonth == $month) {
			$selected = 'selected="selected"';
		}
		$str .= '<option value="'.$month.'" '.$selected.'>'.$helper->pluralMonths($month).'</option>';
	}
	
	return $str;
}

?>

<link rel="stylesheet" media="screen" href="http://<?php echo Config::getInstance()->default->hostname; ?>/style/admin_product.css" />
<!--[if lte IE 7]><link href="/style/ie.css" rel="stylesheet" type="text/css"><![endif]-->
<form enctype="multipart/form-data" method="post" action="">
  <div>
    
    <?php 
    /**
     * Translate some form errrors.
     * 
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);
	
    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}
    	
    	return $error;
    }
    
    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }
    
    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
    ?>

	<dd >
		<?php echo $form->getElement('key'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('name'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('category_name'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('parent_id'); ?>
	</dd>

	<dd >
		<?php echo $form->getElement('attendant_category'); ?>
	</dd>

	<dd >
		<?php echo $form->getElement('description'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('meta_title'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('meta_keywords'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('meta_description'); ?>
	</dd>

	<dd >
		<?php echo $form->getElement('color'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('yml_include'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('yml_name'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('has_products'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('base_category_id'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('order'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('typePrefix'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('wikimart_include'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('wikimart_name'); ?>
	</dd>
	<dd >
		<?php echo $form->getElement('template'); ?>
	</dd>
	<br><br>
	<dd id="submit-element">
		<input type="submit" name="submit" id="submit" value="Сохранить">
	</dd>
	<br>
	<?php echo $form->getElement('crud_exit'); ?>
	<br>
</div>
</form>


